﻿using System.Web;

namespace EncodingTools {
    public class UrlEncoder : IEncoder, IDecoder {
        private readonly EncodingHelper _encodingHelper = new EncodingHelper();

        public byte[] Encode(byte[] value) {
            string str = HttpUtility.UrlEncode(value);
            return _encodingHelper.StringToBytes(str);
        }

        public byte[] Decode(byte[] value) {
            string str = HttpUtility.UrlDecode(value, _encodingHelper.Encoding);
            return _encodingHelper.StringToBytes(str);
        }
    }
}
